package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlDeduction;
import com.ruoyi.sl.service.ISlDeductionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 扣款相关人Controller
 * 
 * @author admin
 * @date 2024-06-27
 */
@RestController
@RequestMapping("/sl/deduction")
public class SlDeductionController extends BaseController
{
    @Autowired
    private ISlDeductionService slDeductionService;

    /**
     * 查询扣款相关人列表
     */
    @PreAuthorize("@ss.hasPermi('sl:deduction:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlDeduction slDeduction)
    {
        startPage();
        List<SlDeduction> list = slDeductionService.selectSlDeductionList(slDeduction);
        return getDataTable(list);
    }

    /**
     * 导出扣款相关人列表
     */
    @PreAuthorize("@ss.hasPermi('sl:deduction:export')")
    @Log(title = "扣款相关人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlDeduction slDeduction)
    {
        List<SlDeduction> list = slDeductionService.selectSlDeductionList(slDeduction);
        ExcelUtil<SlDeduction> util = new ExcelUtil<SlDeduction>(SlDeduction.class);
        util.exportExcel(response, list, "扣款相关人数据");
    }

    /**
     * 获取扣款相关人详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:deduction:query')")
    @GetMapping(value = "/{deductionId}")
    public AjaxResult getInfo(@PathVariable("deductionId") Long deductionId)
    {
        return success(slDeductionService.selectSlDeductionByDeductionId(deductionId));
    }

    /**
     * 新增扣款相关人
     */
    @PreAuthorize("@ss.hasPermi('sl:deduction:add')")
    @Log(title = "扣款相关人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlDeduction slDeduction)
    {
        return toAjax(slDeductionService.insertSlDeduction(slDeduction));
    }

    /**
     * 修改扣款相关人
     */
    @PreAuthorize("@ss.hasPermi('sl:deduction:edit')")
    @Log(title = "扣款相关人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlDeduction slDeduction)
    {
        return toAjax(slDeductionService.updateSlDeduction(slDeduction));
    }

    /**
     * 删除扣款相关人
     */
    @PreAuthorize("@ss.hasPermi('sl:deduction:remove')")
    @Log(title = "扣款相关人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deductionIds}")
    public AjaxResult remove(@PathVariable Long[] deductionIds)
    {
        return toAjax(slDeductionService.deleteSlDeductionByDeductionIds(deductionIds));
    }
}
